package mapper;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.session.TransactionIsolationLevel;
import org.junit.Before;
import org.junit.Test;

import cn.itcast.mybatis.mapper.UserMapper;
import cn.itcast.mybatis.po.User;

/**
 *  使用classPath:mapper/usermapper.xml 为映射文件
 * @author E440
 *
 */
public class MapperTestDemo1 {
	private SqlSessionFactory factory=null;

	@Before
	public void beforeInstance() throws IOException{
		String config="config/sqlmapconfig.xml";
		InputStream in=Resources.getResourceAsStream(config);
		factory=new SqlSessionFactoryBuilder().build(in);
	}
	
	@Test
	public void testFindUserById() throws Exception {
		SqlSession session=factory.openSession();
		//创建UserMapper对象，mybatis自动生成mapper代理对象
		UserMapper mapper=session.getMapper(UserMapper.class);
		User user=mapper.findUserById(10);
		System.out.println(user);
	}
}
